#include <iostream>
#include <assert.h>

using namespace std;

struct 	ListNode
{
	int key;
	ListNode * next;
};

ListNode * last_K(ListNode * head, int k) {
	assert(k >= 0);

	if (head == NULL)
		return NULL;
	
	ListNode *p1 = head, *p2 = head;
	for (int i = 0; i < k; ++i) {
		if (p2 != NULL)
			p2 = p2->next;
		else
			break;
	}
	
	if (p2 == NULL)
		return NULL;

	for (; p2->next != NULL; p2 = p2->next, p1 = p1->next)
		;

	 return p1;
}

ListNode * insert(ListNode *head, int e) {
	ListNode * n = (ListNode *)malloc(sizeof(ListNode));
	n->key = e;
	n->next = head;
	return n;
}

int main()
{
	ListNode * head = NULL;
	for (int i = 0; i < 10; i ++)
		head = insert(head, rand()%100);

	for (ListNode * cur = head; cur != NULL; cur = cur->next)
		cout << cur->key << " ";
	cout << endl;

	int k = 0;
	while(cin >> k) {
		ListNode * lk = last_K(head, k);
		if (lk)
			cout << lk->key << endl;
	}

	return 0;
}
